package com.manpower.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

/**
 * The login Page 
 * @author liuyang
 *
 */
public class LoginActivity extends Activity {
	private EditText mUserNameInput = null;
	private EditText mPassWordInput = null;
	private CheckBox mRememberPassWord = null;
	private Button mConfirmButton = null;
	private Button mCancelButton = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setFullWindow();
        setContentView(R.layout.activity_login);
        initiate();
    }
    
    /**
     * initiate widgets in this page 
     */
    private void initiate() {
    	mUserNameInput = (EditText)findViewById(R.id.username_input);
    	mPassWordInput = (EditText)findViewById(R.id.password_input);
    	mRememberPassWord = (CheckBox)findViewById(R.id.rememberPassword);
    	mConfirmButton = (Button)findViewById(R.id.confirm_button);
    	mCancelButton = (Button)findViewById(R.id.cancel_button);
    	
    	mConfirmButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO login and jump to Main GridView Page
				String userName = mUserNameInput.getText().toString();
				String password = mPassWordInput.getText().toString();
				if(userName != null&&userName.length() > 0&&userName.equals("yl")
						&&password != null&&password.length() > 0&&password.equals("011008")) {
					Intent intent = new Intent(LoginActivity.this, FrameActivityGroup.class);
					LoginActivity.this.startActivity(intent);
					LoginActivity.this.finish();
				}else {
					Toast.makeText(LoginActivity.this, R.string.login_erro, Toast.LENGTH_SHORT).show();
				}
//				int version = Integer.valueOf(android.os.Build.VERSION.SDK);
//				if(version >= 5) {
//					LoginActivity.this.overridePendingTransition(0, R.anim.page_down);
//					
//				}
			}
    		
    	});
    	
    	mCancelButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO exit the App
				new ExitDialog(LoginActivity.this, R.style.custom_dialog).show();
			}
		});
    	
    	
    }
    
    private void setFullWindow() {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//				WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}
   
}